package com.mathdroid.model.enums;

import java.util.LinkedList;

import com.mathdroid.exceptionhandling.ParserException;

/**
 * Items of the type "Armor" require a proficiency to use them.
 */
public enum EArmorProficiency {

	/**
	 * Accessoirs Armor.
	 */
	ACCESSOIRS_ARMOR("Accessoirs Armor"),
	/**
	 * Light armor.
	 */
	LIGHT("Light Armor"),
	
	/**
	 * Medium armor.
	 */
	MEDIUM("Medium Armor"),
	
	/**
	 * Heavy armor.
	 */
	HEAVY("Heavy Armor");

	/**
	 * String representation of the proficiency.
	 */
	private String name = null;
	
	/**
	 * Create an armor proficiency enumeration.
	 * @param s String representation.
	 */
	EArmorProficiency(final String s) {
		this.name = s;
	}
	
	@Override
	public String toString() {
		return this.name;
	}
	
	/**
	 * Get all available armor proficiencies as a list.
	 * @return All armor types.
	 */
	public static LinkedList<EArmorProficiency> getArmorProficiencies() {
		LinkedList<EArmorProficiency> r = new LinkedList<EArmorProficiency>();
		
		r.add(ACCESSOIRS_ARMOR);
		r.add(LIGHT);
		r.add(MEDIUM);
		r.add(HEAVY);
		
		return r;
	}
	
	/**
	 * Parse a string to an enumeration object. The parser compares the
	 * string representation of this enumeration with the parameter, not the
	 * literal.
	 * @param s String.
	 * @return EArmorProficiency object.
	 * @throws ParserException The string cannot be parsed.
	 */
	public static final 
	EArmorProficiency parseEArmorProficiency(final String s) 
	throws ParserException {
		EArmorProficiency a = null;
		
		for (EArmorProficiency type 
				: EArmorProficiency.getArmorProficiencies()) {
			if (s.equals(type.toString())) {
				a = type;
			}
		}
		
		if (a == null) {
			ParserException p = new ParserException(
					"No such armor proficiency: \"" + s + "\"");
			p.fillInStackTrace();
			throw p;
		}
		
		return a;
	}
}
